<?php


namespace app\adminapi\controller\hotel;


use app\adminapi\BaseAdminController;
use app\adminapi\dao\hotel\HotelDao;
use app\adminapi\lists\hotel\HotelLists;
use app\adminapi\validate\hotel\HotelValidate;

/**
 * @projectName src
 */
class Hotel extends BaseAdminController
{
    public function add()
    {
        $params = (new HotelValidate())->post([
            'pid',
            'hotel_name',
            'hotel_scale',
            'hotel_nature',
            'firm_name',
            'contact_person',
            'contact_phone'
        ])->goCheck('add');
        HotelDao::add($params);
        return $this->success('添加成功', $params, 200, 1);
    }

    public function edit()
    {
        $params = (new HotelValidate())->post([
            'id',
            'pid',
            'hotel_name',
            'hotel_scale',
            'hotel_nature',
            'firm_name',
            'contact_person',
            'contact_phone',
            'status'=>0
        ])->goCheck('edit');
        $result = HotelDao::edit($params);
        if (true === $result) {
            return $this->success('编辑成功', [], 200, 1);
        }
        return $this->fail(HotelDao::getError());
    }

    public function delete()
    {
        $params = (new HotelValidate())->post([
            'id'
        ])->goCheck('delete');
        HotelDao::delete($params);
        return $this->success('删除成功', [], 200, 1);
    }

    public function detail()
    {
        $params = (new HotelValidate())->get([
            'id'
        ])->goCheck('detail');
        $result = HotelDao::detail($params);
        return $this->data($result);
    }

    public function all()
    {
        $result = HotelDao::getAllData();
        return $this->data($result);
    }

    /**
     * 获取列表
     */
    public function lists()
    {
        return $this->dataLists(new HotelLists());
    }

}